﻿using ApplicationLibrary.SqlConnector;
using ApplicationLibrary;

namespace Plumber.Accounting.ModuleData
{
    #region DRJournalEntry

    public class DRJournalEntry : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private string JournalNo;

        public DRJournalEntry(bool update)
            : base(update)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntry.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntry.JournalNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntry.Name);
            qB.AddCompare(PL_JournalEntry.JournalNo, sqlP1);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = JournalNo;
        }

        public bool Find(string journalno)
        {
            this.JournalNo = journalno;
            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryDetail

    public class DRJournalEntryDetail : DataReaderUpdater
    {
        private SqlABParameter sqlP1, sqlP2;
        private string JournalNo;
        private int Line;

        public DRJournalEntryDetail(bool update)
            : base(update)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.JournalNo);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.Line);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.JournalNo, sqlP1);
            qB.AddCompare(PL_JournalEntryDetail.Line, sqlP2);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = JournalNo;
            sqlP2.Value = Line;
        }

        public bool Find(string journalno, int line)
        {
            this.JournalNo = journalno;
            this.Line = line;
            return base.Find();
        }
    }

    #endregion

    #region RRJournalEntryDetail

    public class RRJournalEntryDetail : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private string JournalNo;

        public RRJournalEntryDetail(bool updater)
            : base(updater)
        {
        }

        public RRJournalEntryDetail()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.JournalNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.JournalNo, sqlP1);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = JournalNo;
        }

        public bool Find(string journalno)
        {
            this.JournalNo = journalno;
            return base.Find();
        }
    }

    #endregion

    #region RRJournalEntryTaxDetail

    public class RRJournalEntryTaxDetail : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private string JournalNo;

        public RRJournalEntryTaxDetail(bool updater)
            : base(updater)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryTaxDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryTaxDetail.JournalNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryTaxDetail.Name);
            qB.AddCompare(PL_JournalEntryTaxDetail.JournalNo, sqlP1);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = JournalNo;
        }

        public bool Find(string journalno)
        {
            this.JournalNo = journalno;
            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryForSales

    public class DRJournalEntryForSales : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private SqlABParameter sqlP2;
        private SqlABParameter sqlP3;
        private string type;
        private string code;
        private string docNo;

        public DRJournalEntryForSales()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.Type);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.Code);
            sqlP3 = new SqlABParameter("@p52", PL_JournalEntryDetail.DocumentNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.Type, sqlP1);
            qB.AddCompare(PL_JournalEntryDetail.Code, sqlP2);
            qB.AddCompare(PL_JournalEntryDetail.DocumentNo, sqlP3);
            qB.AddCompare<double>(PL_JournalEntryDetail.To, 0, "!=");

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlCM.Parameters.Add(sqlP3);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = type;
            sqlP2.Value = code;
            sqlP3.Value = docNo;
        }

        public bool Find(string type, string code, string docNo)
        {
            this.type = type;
            this.code = code;
            this.docNo = docNo;

            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryForPaymentSales

    public class DRJournalEntryForPaymentSales : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private SqlABParameter sqlP2;
        private SqlABParameter sqlP3;
        private string type;
        private string code;
        private string docNo;

        public DRJournalEntryForPaymentSales()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder(true);
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.Type);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.Code);
            sqlP3 = new SqlABParameter("@p52", PL_JournalEntryDetail.DocumentNo);

            qB.AddSelect(PL_JournalEntry.PostingDate);
            qB.AddSelectAll(PL_JournalEntryDetail.Name);
            qB.AddFrom(PL_JournalEntry.Name);
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompareColumn(PL_JournalEntry.JournalNo, PL_JournalEntryDetail.JournalNo);
            qB.AddCompare(PL_JournalEntryDetail.Type, sqlP1);
            qB.AddCompare(PL_JournalEntryDetail.Code, sqlP2);
            qB.AddCompare(PL_JournalEntryDetail.DocumentNo, sqlP3);
            qB.AddCompare<double>(PL_JournalEntryDetail.From, 0, "!=");

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlCM.Parameters.Add(sqlP3);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = type;
            sqlP2.Value = code;
            sqlP3.Value = docNo;
        }

        public bool Find(string type, string code, string docNo)
        {
            this.type = type;
            this.code = code;
            this.docNo = docNo;

            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryForCreditNote

    public class DRJournalEntryForCreditNote : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private SqlABParameter sqlP2;
        private SqlABParameter sqlP3;
        private string type;
        private string code;
        private string docNo;

        public DRJournalEntryForCreditNote()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.Type);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.Code);
            sqlP3 = new SqlABParameter("@p52", PL_JournalEntryDetail.DocumentNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.Type, sqlP1);
            qB.AddCompare(PL_JournalEntryDetail.Code, sqlP2);
            qB.AddCompare(PL_JournalEntryDetail.DocumentNo, sqlP3);
            qB.AddCompare<double>(PL_JournalEntryDetail.From, 0, "!=");

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlCM.Parameters.Add(sqlP3);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = type;
            sqlP2.Value = code;
            sqlP3.Value = docNo;
        }

        public bool Find(string type, string code, string docNo)
        {
            this.type = type;
            this.code = code;
            this.docNo = docNo;

            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryByDocumentNo

    public class DRJournalEntryByDocumentNo : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private SqlABParameter sqlP2;
        private string type;
        private string code;

        public DRJournalEntryByDocumentNo()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.Type);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.DocumentNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.Type, sqlP1);
            qB.AddCompare(PL_JournalEntryDetail.DocumentNo, sqlP2);
            qB.AddOrder(PL_JournalEntryDetail.JournalNo);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = type;
            sqlP2.Value = code;
        }

        public bool Find(string type, string code)
        {
            this.type = type;
            this.code = code;
            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryTotal

    public class DRJournalEntryTotal : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private string documentNo;

        public DRJournalEntryTotal()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();

            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.DocumentNo);

            qB.AddFunction("SUM([{0}]) AS [{1}]", PL_JournalEntryDetail.From, PL_JournalEntryDetail.From.Name);
            qB.AddFunction("SUM([{0}]) AS [{1}]", PL_JournalEntryDetail.To, PL_JournalEntryDetail.To.Name);
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.DocumentNo, sqlP1);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = documentNo;
        }

        public bool Find(string documentNo)
        {
            this.documentNo = documentNo;
            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryTotalByType

    public class DRJournalEntryTotalByType : DataReaderUpdater
    {
        private SqlABParameter sqlP1, sqlP2, sqlP3;
        private string documentNo;
        private string type;
        private string code;

        public DRJournalEntryTotalByType()
            : base(false)
        {
        }

        protected virtual void ModifyQuery(ref QueryBuilder qb)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();

            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.DocumentNo);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.Type);
            sqlP3 = new SqlABParameter("@p52", PL_JournalEntryDetail.Code);

            qB.AddFunction("SUM([{0}]) AS [{1}]", PL_JournalEntryDetail.From, PL_JournalEntryDetail.From.Name);
            qB.AddFunction("SUM([{0}]) AS [{1}]", PL_JournalEntryDetail.To, PL_JournalEntryDetail.To.Name);
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.Type, sqlP2);
            qB.AddCompare(PL_JournalEntryDetail.Code, sqlP3);
            qB.Where += string.Format(" AND ({0} = @p50 OR {1} = @p50)", PL_JournalEntryDetail.DocumentNo.Name, PL_JournalEntryDetail.InvoiceNo.Name);

            ModifyQuery(ref qB);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlCM.Parameters.Add(sqlP3);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = documentNo;
            sqlP2.Value = type;
            sqlP3.Value = code;
        }

        public bool Find(string documentNo, string type, string code)
        {
            this.documentNo = documentNo;
            this.type = type;
            this.code = code;
            return base.Find();
        }
    }

    #endregion

    #region DRJournalEntryTotalWithoutMe

    public class DRJournalEntryTotalWithoutMe : DRJournalEntryTotalByType
    {
        private SqlABParameter sqlP4;
        private string JournalNo;

        public DRJournalEntryTotalWithoutMe()
            : base()
        {
        }

        protected override void ModifyQuery(ref QueryBuilder qb)
        {
            qb.AddCompare(PL_JournalEntryDetail.JournalNo, sqlP4, "!=");
        }

        protected override void CreateConnection()
        {
            sqlP4 = new SqlABParameter("@p53", PL_JournalEntryDetail.JournalNo);
            base.CreateConnection();
            sqlCM.Parameters.Add(sqlP4);
        }

        protected override void SetParameters()
        {
            sqlP4.Value = JournalNo;
            base.SetParameters();
        }

        public bool Find(string documentNo, string type, string code, string journalNo)
        {
            this.JournalNo = journalNo;
            return base.Find(documentNo, type, code);
        }
    }

    #endregion

    #region DUJournalEntryWithoutMe

    public class RUJournalEntryWithoutMe : DataReaderUpdater
    {
        private SqlABParameter sqlP1, sqlP2, sqlP3, sqlP4;
        private string documentNo;
        private string type;
        private string code;
        private string journalNo;

        public RUJournalEntryWithoutMe()
            : base(true)
        {
        }

        protected virtual void ModifyQuery(ref QueryBuilder qb)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();

            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.DocumentNo);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.Type);
            sqlP3 = new SqlABParameter("@p52", PL_JournalEntryDetail.Code);
            sqlP4 = new SqlABParameter("@p53", PL_JournalEntryDetail.JournalNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.DocumentNo, sqlP1);
            qB.AddCompare(PL_JournalEntryDetail.Type, sqlP2);
            qB.AddCompare(PL_JournalEntryDetail.Code, sqlP3);
            qB.AddCompare(PL_JournalEntryDetail.JournalNo, sqlP4, "!=");

            ModifyQuery(ref qB);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlCM.Parameters.Add(sqlP3);
            sqlCM.Parameters.Add(sqlP4);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = documentNo;
            sqlP2.Value = type;
            sqlP3.Value = code;
            sqlP4.Value = journalNo;
        }

        public bool Find(string documentNo, string type, string code, string journalNo)
        {
            this.documentNo = documentNo;
            this.type = type;
            this.code = code;
            this.journalNo = journalNo;
            return base.Find();
        }
    }

    #endregion

    #region RRJournalEntryBeforeMe

    public class RRJournalEntryAfterMe : DataReaderUpdater
    {
        private SqlABParameter sqlP1, sqlP2, sqlP3;
        private string type;
        private string code;
        private string JENo;

        public RRJournalEntryAfterMe()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntryDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JournalEntryDetail.Type);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntryDetail.DocumentNo);
            sqlP3 = new SqlABParameter("@p52", PL_JournalEntryDetail.JournalNo);

            qB.AddSelect();
            qB.AddFrom(PL_JournalEntryDetail.Name);
            qB.AddCompare(PL_JournalEntryDetail.Type, sqlP1);
            qB.AddCompare(PL_JournalEntryDetail.DocumentNo, sqlP2);
            qB.AddCompare(PL_JournalEntryDetail.JournalNo, sqlP3, ">=");
            qB.AddOrder(PL_JournalEntryDetail.JournalNo);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlCM.Parameters.Add(sqlP3);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = type;
            sqlP2.Value = code;
            sqlP3.Value = JENo;
        }

        public bool Find(string type, string code, string JENo)
        {
            this.type = type;
            this.code = code;
            this.JENo = JENo;
            return base.Find();
        }
    }

    #endregion

    #region RRJETemplate

    public class RRJETemplate : DataReaderUpdater
    {
        bool salePurchase;

        public RRJETemplate(bool salepurchase)
            : base(false)
        {
            this.salePurchase = salepurchase;
        }

        protected override void CreateConnection()
        {
            myTable = PL_JETemplate.Name;

            QueryBuilder qB = new QueryBuilder();

            qB.AddSelect();
            qB.AddFrom(PL_JETemplate.Name);
            if (salePurchase)
                qB.AddCompare<int>(PL_JETemplate.InvoiceType, InvoiceType.E_NoInvoice.Int(), "<>");
            else
                qB.AddCompare<int>(PL_JETemplate.InvoiceType, InvoiceType.E_NoInvoice.Int());

            qB.AddOrder(PL_JETemplate.Description);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
        }
    }

    #endregion

    #region DRJETemplate

    public class DRJETemplate : DataReaderUpdater
    {
        private SqlABParameter sqlP1 = null;
        private string template;

        public DRJETemplate()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JETemplate.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JETemplate.Template);

            qB.AddSelect();
            qB.AddFrom(PL_JETemplate.Name);
            qB.AddCompare(PL_JETemplate.Template, sqlP1);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        public bool Find(string template)
        {
            this.template = template;
            return base.Find();
        }

        protected override void SetParameters()
        {
            sqlP1.Value = template;
        }
    }

    #endregion

    #region RRJETemplateDetail

    public class RRJETemplateDetail : DataReaderUpdater
    {
        private SqlABParameter sqlP1 = null;
        private string template;

        public RRJETemplateDetail()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JETemplateDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JETemplateDetail.Template);

            qB.AddSelect();
            qB.AddFrom(PL_JETemplateDetail.Name);
            qB.AddCompare(PL_JETemplateDetail.Template, sqlP1);
            qB.AddOrder(PL_JETemplateDetail.Line);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        public bool Find(string template)
        {
            this.template = template;
            return base.Find();
        }

        protected override void SetParameters()
        {
            sqlP1.Value = template;
        }
    }

    #endregion

    #region RRJETemplateTaxDetail

    public class RRJETemplateTaxDetail : DataReaderUpdater
    {
        private SqlABParameter sqlP1 = null;
        private string template;

        public RRJETemplateTaxDetail()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JETemplateDetail.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_JETemplateTaxDetail.Template);

            qB.AddSelect();
            qB.AddFrom(PL_JETemplateTaxDetail.Name);
            qB.AddCompare(PL_JETemplateTaxDetail.Template, sqlP1);
            qB.AddOrder(PL_JETemplateTaxDetail.Line);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        public bool Find(string template)
        {
            this.template = template;
            return base.Find();
        }

        protected override void SetParameters()
        {
            sqlP1.Value = template;
        }
    }

    #endregion

    #region DRJournalEntryTotalByType

    public class DRSaleJournalEntryTotalByType : DataReaderUpdater
    {
        private SqlABParameter sqlP1, sqlP2, sqlP3;
        private string documentNo;
        private string type;
        private string code;

        public DRSaleJournalEntryTotalByType()
            : base(false)
        {
        }

        protected virtual void ModifyQuery(ref QueryBuilder qb)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_JournalEntry.Name;

            QueryBuilder qB = new QueryBuilder();
            qB.AddSelect();
            qB.AddFrom(PL_JournalEntry.Name);

            sqlP1 = new SqlABParameter("@p50", PL_JournalEntry.DocumentNo);
            sqlP2 = new SqlABParameter("@p51", PL_JournalEntry.Type);
            sqlP3 = new SqlABParameter("@p52", PL_JournalEntry.Code);

            qB.AddCompare(PL_JournalEntry.DocumentNo, sqlP1);
            qB.AddCompare(PL_JournalEntry.Type, sqlP2);
            qB.AddCompare(PL_JournalEntry.Code, sqlP3);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlCM.Parameters.Add(sqlP3);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = documentNo;
            sqlP2.Value = type;
            sqlP3.Value = code;
        }

        public bool Find(string documentNo, string type, string code)
        {
            this.documentNo = documentNo;
            this.type = type;
            this.code = code;
            return base.Find();
        }
    }

    #endregion

    #region DUJournalEntryWithoutMe

    public class DRLiquidationTax : DataReaderUpdater
    {
        private SqlABParameter sqlP1, sqlP2;
        private int month;
        private int year;

        public DRLiquidationTax(bool update)
            : base(update)
        {
        }

        protected virtual void ModifyQuery(ref QueryBuilder qb)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_LiquidationTax.Name;

            QueryBuilder qB = new QueryBuilder();

            sqlP1 = new SqlABParameter("@p50", PL_LiquidationTax.Month);
            sqlP2 = new SqlABParameter("@p51", PL_LiquidationTax.Year);

            qB.AddSelect();
            qB.AddFrom(PL_LiquidationTax.Name);
            qB.AddCompare(PL_LiquidationTax.Month, sqlP1);
            qB.AddCompare(PL_LiquidationTax.Year, sqlP2);

            ModifyQuery(ref qB);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = month;
            sqlP2.Value = year;
        }

        public bool Find(int month, int year)
        {
            this.month = month;
            this.year = year;
            return base.Find();
        }
    }

    #endregion

    #region DRLiquidationType

    public class DRLiquidationType : DataReaderUpdater
    {
        private SqlABParameter sqlP1 = null;
        private int year;

        public DRLiquidationType()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = PL_LiquidationType.Name;

            QueryBuilder qB = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p50", PL_LiquidationType.Year);

            qB.AddSelect();
            qB.AddFrom(PL_LiquidationType.Name);
            qB.AddCompare(PL_LiquidationType.Year, sqlP1);

            sqlCM = new SqlABCommand(qB.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        public bool Find(int year)
        {
            this.year = year;
            return base.Find();
        }

        protected override void SetParameters()
        {
            sqlP1.Value = year;
        }
    }

    #endregion


}